package com.aplink.generic.util.objectrule;

import java.util.ArrayList;

import com.aplink.generic.pojo.GenericObject;

public class TargetRuleCollection {
	private ArrayList<TargetRule> arrTargetRules;
	private String defaultTarget;

	public TargetRuleCollection() {
		this.defaultTarget = "";
		this.arrTargetRules = new ArrayList<TargetRule>();
	}

	public TargetRuleCollection(final String _defaultTarget,
	        final ArrayList<TargetRule> _arrTargetRules) {
		this.defaultTarget = _defaultTarget;

		this.arrTargetRules = new ArrayList<TargetRule>();
		this.arrTargetRules = _arrTargetRules;

	}

	public ArrayList<TargetRule> getArrTargetRules() {
		return this.arrTargetRules;
	}

	public String getDefaultTarget() {
		return this.defaultTarget;
	}

	public String getTargetBaseOnPassedGenericObject(
	        final GenericObject genericObject) {

		for (final TargetRule targetRule : this.arrTargetRules) {
			final boolean isSatisfied = targetRule
			        .isSatisfiedCondition(genericObject);
			if (isSatisfied) {
				return targetRule.getTargetActivity();
			}
		}

		return this.defaultTarget;
	}

	public void setArrTargetRules(final ArrayList<TargetRule> arrTargetRules) {
		this.arrTargetRules = arrTargetRules;
	}

	public void setDefaultTarget(final String defaultTarget) {
		this.defaultTarget = defaultTarget;
	}

}
